package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.WhitelistSettingService;
import com.example.mybatisplus.model.domain.WhitelistSetting;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-11-01
 * @version v1.0
 */
@Controller
@RequestMapping("/api/whitelistSetting")
public class WhitelistSettingController {

    private final Logger logger = LoggerFactory.getLogger( WhitelistSettingController.class );

    @Autowired
    private WhitelistSettingService whitelistSettingService;


    @ResponseBody
    @PostMapping("/login")
    public JsonResponse login(@RequestBody WhitelistSetting whitelistSetting){
        // 如果有这个用户  就返回这个用户  没有就返回null
        WhitelistSetting login =   whitelistSettingService.login(whitelistSetting);
        // 会把登录用户存进session
        SessionUtils.saveCurrentUser(login);
        return JsonResponse.success(login);
    }

    @ResponseBody
    @GetMapping("/logout")
    public JsonResponse logout(){
        // 把session里的当前用户删除掉
        SessionUtils.clear();
        return JsonResponse.success(true);
    }

    // 分页查询数据
    @GetMapping("/pageList")
    @ResponseBody
    public JsonResponse pageList(PageDTO pageDTO,WhitelistSetting whitelistSetting){
        Page<WhitelistSetting> page = whitelistSettingService.pageList(pageDTO,whitelistSetting);
        return JsonResponse.success(page);
    }


    // 注册
    @ResponseBody
    @PostMapping("/regist")
    public JsonResponse regist(@RequestBody WhitelistSetting whitelistSetting){

       whitelistSettingService.regist(whitelistSetting);
        return JsonResponse.success(true);
    }

    // 注册111
    @ResponseBody
    @PostMapping("/regist11")
    public JsonResponse regist11(@RequestBody WhitelistSetting whitelistSetting){

        whitelistSettingService.regist(whitelistSetting);
        return JsonResponse.success(true);
    }

    // 分页查询数据123
    @GetMapping("/pageList123")
    @ResponseBody
    public JsonResponse pageList123(PageDTO pageDTO,WhitelistSetting whitelistSetting){
        Page<WhitelistSetting> page = whitelistSettingService.pageList(pageDTO,whitelistSetting);
        return JsonResponse.success(page);
    }

    // 分页查询数据345
    @GetMapping("/pageList345")
    @ResponseBody
    public JsonResponse pageList345(PageDTO pageDTO,WhitelistSetting whitelistSetting){
        Page<WhitelistSetting> page = whitelistSettingService.pageList(pageDTO,whitelistSetting);
        return JsonResponse.success(page);
    }
}

